package com.hq.fxh.No5_User.User.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.hq.fxh.CustomerView.CircleImageView;
import com.hq.fxh.Modle.FollowUserModle;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.ClickUtils;
import com.hq.fxh.Utils.GlideUtils;
import com.hq.fxh.Utils.Tool;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

import static android.R.attr.id;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/15
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_GZ_People extends BaseAdapter {
    List<FollowUserModle.DataBean> data;
    GZCallBack callBack;
    int type = 0;//0 粉丝  1 黑名单  2 我的关注

    public void setCallBack(GZCallBack callBack) {
        this.callBack = callBack;
    }


    public void setData(List<FollowUserModle.DataBean> data, int type) {
        this.data = data;
        this.type = type;
    }


    @Override
    public int getCount() {
        if (data == null) {
            return 1;
        } else {
            return data.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_guanzhu_user_name, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        if (data != null) {
            FollowUserModle.DataBean dataBean = data.get(i);
            Tool.setUrlToHeadImage(parent.getContext(), data.get(i).getIcon(), viewHolder.imageGZPIcon);
            Tool.setStringToText(viewHolder.tvGZPName, dataBean.getNickname());
            switch (type) {
                case 0:
                    if (dataBean.getState() == 1) {
                        ClickUtils.clickGuanzhu(parent.getContext(), viewHolder.btnGZPFocus, true);

                    } else {
                        ClickUtils.clickGuanzhu(parent.getContext(), viewHolder.btnGZPFocus, false);
                    }
                    break;
                case 1:
                    ClickUtils.clickGuanzhu(parent.getContext(), viewHolder.btnGZPFocus, false, "移除");
                    break;
                case 2:
                    ClickUtils.clickGuanzhu(parent.getContext(), viewHolder.btnGZPFocus, true);

                    break;
            }

        }

        final ViewHolder finalViewHolder = viewHolder;
        viewHolder.btnGZPFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FollowUserModle.DataBean dataBean = data.get(i);

                callBack.call(finalViewHolder.btnGZPFocus, i, dataBean);
            }
        });

        return view;
    }

    static class ViewHolder {
        protected CircleImageView imageGZPIcon;
        protected TextView tvGZPName;
        protected ImageView imageGZPTag;
        protected LinearLayout layoutGZPUser;
        protected TextView btnGZPFocus;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            imageGZPIcon = (CircleImageView) rootView.findViewById(R.id.image_GZP_icon);
            tvGZPName = (TextView) rootView.findViewById(R.id.tv_GZP_name);
            imageGZPTag = (ImageView) rootView.findViewById(R.id.image_GZP_tag);
            layoutGZPUser = (LinearLayout) rootView.findViewById(R.id.layout_GZP_User);
            btnGZPFocus = (TextView) rootView.findViewById(R.id.btn_GZP_Focus);
        }
    }


    public interface GZCallBack {
        public void call(TextView textView, int position, FollowUserModle.DataBean user);
    }

}
